version 8.2
capture clear
capture log close
set more off
set mem 5000m
set mat 800


****Merge with Nunn's data:
*see "Preparation Contract intensive.do"

use "panel_data_clean2.dta"
sort d1a2
merge d1a2 using "Contract intensity.dta"
*codebook _merge
drop _merge 
ren frac_lib_diff CI
save "panel_data_clean2.dta", replace




****merge with Valued added Sweden:
use "panel_data_clean2.dta"
sort d1a2
merge d1a2 using "JD_Sweden_4digit.dta"
codebook _merge
*browse d1a2 _merge
*not everything merges....
drop _merge
save "panel_data_clean2.dta", replace


****now merge with Valued added Continent:
use "panel_data_clean2.dta"
sort continent d1a2
merge continent d1a2 using "JD_Continent_4digit.dta"
codebook _merge
*browse d1a2 _merge
*not everything merges....
drop _merge
save "panel_data_clean2.dta", replace


****now merge with Germany_Innovation:
use "panel_data_clean2.dta"
capture drop DJ4g*
sort d1a2
merge d1a2 using "JD_Germany_Innovation_4digit.dta"
codebook _merge
*browse d1a2 _merge
*not everything merges....
drop _merge
save "panel_data_clean2.dta", replace

***merge with judicial reforms:
use "panel_data_clean2.dta"
sort countryname year
merge countryname year using "Enterprise surveys_earlier waves_judicial_reforms_for merge with earlier waves.dta"
codebook _merge
*browse if countryname=="Albania"&year==2009

drop _merge
save "panel_data_clean2.dta", replace


****Interaction DJ and judicial reforms:

use "panel_data_clean2.dta"


****Now work on va_perwo using PPP exchange rate:
gen va_perwo_ppp=va_perwo/pppconversionfactorgdplcuperinte

***trim 1%:
centile(va_perwo_ppp), centile(0.5 99.5)
gen va_perwo_ppp_trim1=va_perwo_ppp
replace va_perwo_ppp_trim1=. if va_perwo_ppp<`r(c_1)'& va_perwo_ppp!=.
replace va_perwo_ppp_trim1=. if va_perwo_ppp>`r(c_2)' & va_perwo_ppp!=.
*hist va_perwo_ppp_trim1



***Change of currencies:

/*
****ranking by country:
collapse (mean) mean_va_perwo=va_perwo (mean) mean_va_perwo_ppp_trim1=va_perwo_ppp_trim1 (mean) mean_ppp=pppconversionfactorgdplcuperinte, by(countryname year)
sort countryname year
browse countryname year mean_va_perwo mean_va_perwo_ppp_trim1 mean_ppp

exit

*/

***Ghana divided currency by 10,000 in 2007:
*https://fr.wikipedia.org/wiki/Cedi

*SO: replace va_perwo_ppp=va_perwo_ppp/10000 if countryname=="Ghana"&year==2007
*This is equivalent to:

replace pppconversionfactorgdplcuperinte=pppconversionfactorgdplcuperinte*10000 if countryname=="Ghana"&year==2007 


***Angola:
***something weird going on in 2010:
*browse countryname year va_perwo pppconversionfactorgdplcuperinte reform_dum2 if countryname=="Angola"

***But no change in currency:https://en.wikipedia.org/wiki/Angolan_kwanza
***leave it like this, and maybe drop angola from the regressions

***Congo, Dem. Rep.: 
*something weird in 2010
*drop from regressions

*Estonia: something weird in 2009:

***Something weird going on in Poland 2013:
*https://en.wikipedia.org/wiki/Polish_z%C5%82oty
*Romania 2013 
*https://en.wikipedia.org/wiki/Romanian_leu#Fourth_leu_.28RON.29:_2005-Present
*Slovak republic 2009
*Slovenia 2013
*Zambia: probably in the old currency:
*https://en.wikipedia.org/wiki/Zambian_kwacha
*So: replace va_perwo_ppp=va_perwo_ppp/1000 if countryname=="Zambia"
*This is equivalent to:


replace pppconversionfactorgdplcuperinte=pppconversionfactorgdplcuperinte*1000 if countryname=="Zambia"

***conclusion: take out Angola and Romania. Poland, Slovak republic, and Slovenia are already taken out because they are OECD countries

***recalculate va_perwo_ppp:
drop va_perwo_ppp va_perwo_ppp_trim1
gen va_perwo_ppp=va_perwo/pppconversionfactorgdplcuperinte

***trim 1%:
centile(va_perwo_ppp), centile(0.5 99.5)
gen va_perwo_ppp_trim1=va_perwo_ppp
replace va_perwo_ppp_trim1=. if va_perwo_ppp<`r(c_1)'& va_perwo_ppp!=.
replace va_perwo_ppp_trim1=. if va_perwo_ppp>`r(c_2)' & va_perwo_ppp!=.
*hist va_perwo_ppp_trim1


*hist va_perwo_ppp

*hist va_perwo_ppp if countryname!="Angola"&countryname!="Romania"&countryname!="Sweden"&countryname!="Estonia"&countryname=="Czech Republic" ///
&countryname!="Slovak Republic"&countryname!="Slovenia"&countryname!="Hungary"&countryname!="Poland"

sort va_perwo_ppp
*browse countryname year va_perwo_ppp

***There are still some extreme outliers

***drop angola, Congo Dem Rep, romania (weird exchange rates) and OECD:
keep if countryname!="Angola"&countryname!="Congo, Dem. Rep."&countryname!="Congo, Dem. Rep.2" ///
&countryname!="Romania"&countryname!="Sweden"&countryname!="Estonia"&countryname!="Czech Republic" ///
&countryname!="Slovak Republic"&countryname!="Slovenia"&countryname!="Hungary"&countryname!="Poland"




*keep if countryname!="Bosnia and Herzegovina"&countryname!="Croatia"&countryname!="Kosovo"&countryname!="Macedonia, FYR"&countryname!="Montenegro"&countryname!="Ukraine"

*keep if countryname!="Albania"&countryname!="Armenia"&countryname!="Azerbaijan"&countryname!="Belarus"&countryname!="Bulgaria"&countryname!="Georgia"&countryname!="Latvia"&countryname!="Lithuania"&countryname!="Moldova"

*USAID: keep if countryname!="Albania"&countryname!="Armenia"&countryname!="Bosnia and Herzegovina"&countryname!="Georgia"&&countryname!="Indonesia"&countryname!="Kosovo"&&countryname!="Moldova"&countryname!="Montenegro"




	
	
save "Enterprise surveys_judicial_reforms_earlier waves.dta", replace


exit





